package net.dgg.dggcloud.service.jrcrm.service.customer;

import net.dgg.dggcloud.service.common.base.service.BaseService;
import net.dgg.dggcloud.service.jrcrm.dao.customer.ResourceImportRecordDao;
import net.dgg.dggcloud.service.jrcrm.entity.customer.ResourceImportRecord;
import net.dgg.dggcloud.service.entity.user.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 广泛资源导入记录业务处理
 * @ClassName: ResourceImportRecordService
 * @Author: 周潮
 * @Date: 2017年11月20 14:32:43
 * @Version V1.0
 */

@Service
public class ResourceImportRecordService extends BaseService{

    @Autowired
    private ResourceImportRecordDao resourceImportRecordDao;

    /**
     * 保存导入记录
     * @param operator 操作人
     * @param total 导入总数
     */
    public ResourceImportRecord saveWidelyResourceImportRecord(User operator, Integer total){
        ResourceImportRecord record = new ResourceImportRecord();
        record.setId(keyWorker.nextId());
        record.setStatus(1);//待处理
        record.setCreateUser(operator);//创建人
        record.setImportNum(total);//导入条数
        record.setImportTime(new Date());//导入事件
        record.setImporterId(operator.getId());//导入人id
        record.setImporterName(operator.getName());//导入人姓名
        record.setImporterOrgId(operator.getOrgId());//导入人部门id
        record.setSuccessfullyNum(0);
        record.setFailedNum(0);
        record.setRepeatNum(0);
        repository.save(record);
        return record;
    }

    /**
     * 查询广泛资源导入记录
     * @param map
     * @return
     */
    public List<Map> queryResourceImportRecordList(Map map){
        return resourceImportRecordDao.queryResourceImportRecordList(map);
    }

    /**
     * 查询广泛资源导入记录-count
     * @param map
     * @return
     */
    public Integer queryResourceImportRecordCount(Map map){
        return resourceImportRecordDao.queryResourceImportRecordCount(map);
    }

}
